import React, { useEffect, useState } from 'react'

const promise = () => {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve(['哈哈','广告','琴琴','^_^'])
    }, 2000);
  })
}

var cached = {};
const createFetcher = (promiseTask) => {
  let ref = cached;
  return () => {
      const task = promiseTask();
      task.then(res => {
          ref = res
      });
      if (ref === cached) {
          throw task
      }
      return ref
  }
}

const getData = createFetcher(promise)

const ListComp = () => {
  // const [data, setData] = useState(null)

  // useEffect(async() => {
    
    // const res = await getData()

    // setData(res.data)
  // }, [])
  return <div>
    {getData().map(item => {
      <div>{item}</div>
    })}
    </div>
}

export default ListComp